<?php
require('../../../global.php');
//进入页面后先判断是否有访问权限
checkAdminAuthorizeAndJump('questionBank.browse');
?>
<!DOCTYPE html>
<html>
<head>
    <?php require('admin/_head.php'); ?>
    <title>试题管理 - <?php echo getconfig('title'); ?>管理后台</title>
    <link href="<?php echo SITEROOTURL; ?>/admin/css/plugins/bootstrap-table/bootstrap-table.min.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
               	测试题目类目管理
            </div>
            <div class="ibox-content">
                <div class="row row-lg">
                    <div class="col-sm-12">
                        <div id="toolbar" class="btn-group">
                            <div class="form-inline">
                                <div class="form-group">
                                    <?php if(checkAdminAuthorize('questionBank.edit')){?>
                                    <button type="button" id="add" class="btn btn-primary">
                                        <i class="glyphicon glyphicon-plus"></i> 新增
                                    </button>
                                    <?php }?>
                                </div>
                                <div class="form-group" style="margin-left:10px">
                                    <!-- <label class="control-label">证书类型：</label>
                                    <select class="form-control" id="s_type">
                                        <option value="">全部</option>
                                        <option value="1">A</option>
                                        <option value="2">C</option>
                                        <option value="3">X</option>
                                    </select> -->
                                </div>
                            </div>

                        </div>
                        <table id="table" data-toggle="table" data-url="ajax.php?ac=listQuestionCategory" data-query-params="queryParams" data-classes="table table-hover table-condensed" data-striped="true" data-pagination="true" data-side-pagination="server" data-page-list="[10, 20]" data-search="true" data-show-refresh="true" data-show-toggle="false" data-toolbar="#toolbar">
                            <thead>
                                <tr>
                                    <th data-field="name" data-sortable="true">名称</th>
                                    <th data-field="createtime" data-sortable="true">创建时间</th>
                                    <th data-field="do" data-halign="center" data-align="center" data-width="150">操作</th>
                                </tr>
                            </thead>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php require('admin/_js.php'); ?>
    <!-- 自定义js -->
    <script src="<?php echo SITEROOTURL; ?>/admin/js/content.js?v=1.0.0"></script>
    <!-- Bootstrap table -->
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/bootstrap-table/bootstrap-table.min.js"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/bootstrap-table/bootstrap-table-locale-all.min.js"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/bootstrap-table/locale/bootstrap-table-zh-CN.min.js"></script>
    <script>
    $(function(){
        var closeLayer = function(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.closeLayer(index);
        }
        $('.closelayer').click(function(event){
            closeLayer();
        });

        $('#table').on('click', '.remove', function(event){
            event.preventDefault();
            var id = $(this).data().id;
            swal({
                title: "您确定要删除这条记录吗",
                text: "删除后将无法恢复，请谨慎操作！",
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "是的，我要删除！",
                cancelButtonText: "我再考虑一下…",
                closeOnConfirm: false,
                showLoaderOnConfirm: true
            }, function(){
                $.ajax({
                    url: 'ajax.php',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        ac: 'delete',
                        id: id
                    }
                }).done(function(){
                    swal("删除成功！", "", "success");
                    $('#table').bootstrapTable('refresh', {silent: true});
                }).fail(function(){
                    swal("删除失败！", "请重新操作！", "error");
                });
            });
        })
        .on('click', '.edit', function(event){
            event.preventDefault();
            var id = $(this).data().id;
            var cid = $(this).data().cid;
            var gid = $(this).data().gid;
            layer.open({
                type: 2,
                title: false,
                closeBtn: false,
                area: ['100%', '100%'],
                shade: false,
                move: false,
                content: 'addcategory.php?id='+id,
            });
        })
        $('#add').click(function(event){
            event.preventDefault();
            layer.open({
                type: 2,
                title: false,
                closeBtn: false,
                area: ['100%', '100%'],
                shade: false,
                move: false,
                content: 'addcategory.php'
            });
        });
        $('#s_type').on('change', function(){
            $('#table').bootstrapTable('refresh', {silent: true});
        });
    });
    function closeLayer(index){
        layer.close(index);
        $('#table').bootstrapTable('refresh', {silent: true});
    }

    function queryParams(params){
        params['s_type'] = $('#s_type').val();
        return params;
    }
    </script>
</body>
</html>
